/*
https://leetcode-cn.com/problems/implement-queue-using-stacks/solution/yong-zhan-shi-xian-dui-lie-by-leetcode/
 */
import java.util.Stack;

public class Solution232 {

    Stack<Integer> s1=new Stack<>();
    Stack<Integer> s2=new Stack<>();
    int first=-1;

    public Solution232() {

    }

    public void push(int x) {
        if (s1.isEmpty()){
            first=x;
        }
        s1.push(x);
    }

    public int pop() {
        if (s2.isEmpty()){
            while (!s1.isEmpty()){
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }

    public int peek() {
        return s2.isEmpty()?first:s2.peek();
    }

    public boolean empty() {
        return s1.isEmpty() && s2.isEmpty();
    }

    public static void main(String[] args) {
        Solution232 solution232 = new Solution232();
        solution232.push(1);
        solution232.push(2);
        System.out.println(solution232.peek());
        System.out.println(solution232.pop());
        System.out.println(solution232.empty());
    }
}
